'use strict';

const Path = require('path');
const FS = require('fs');

// app/extend/response.js
module.exports = {

  /**
   * 响应html文件
   * @param {*} fileName 文件名
   */
  sendHtmlFile(fileName) {
    this.type = 'html';
    this.body = FS.createReadStream(Path.resolve(__dirname, '../view/', fileName));
  },

  /**
   * 发送正确数据
   * @param data 要发送的数据
   * @param msg 要传输的额外信息
   */
  sendSuccess(data = {}, msg = '') {
    this.type = 'json';
    const body = {
      data,
      code: 0,
      msg,
    };
    this.body = body;
  },
};
